package Dao.Implement;

import Dao.roomUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import pojo.room_user;

import java.sql.Date;
import java.util.List;
@Repository
public class roomUserDaoImplement  implements roomUserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<room_user> selectUserRecord(String startTime, String endTime) {
        String sql="select * from room_user where date>? and date<?";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<room_user>(room_user.class),startTime,endTime);
    }

    @Override
    public Object queryLoseByCategory(Long id, String category, String startTime, String endTIme,int winlose) {
        String sql="select count(*) from room_user where user_id=? and category=? and date>? and date<? and user_state=?";
        try {
            return jdbcTemplate.queryForObject(sql,Integer.class,id,category,startTime,endTIme,winlose);
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }


}
